﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Manager_Sanpham1_Controls_UC_Themloaisanpham : System.Web.UI.UserControl
{
    BUS_Manufacturer data = new BUS_Manufacturer();
    DTO_Manufacturer data2 = new DTO_Manufacturer();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnThemloaisanpham_Click(object sender, EventArgs e)
    {
        if (txtTennhasanxuat.Text.Length == 0)
        {
            Alert.Text = Thongbao("Bạn chưa nhập tên nhà sản xuất");
        }else if (FileUpload1.FileName.Length == 0)
            {
                Alert.Text = Thongbao("Bạn chưa chọn hình ảnh");
            }
            else
            {
                data2.Name = txtTennhasanxuat.Text;
                UploadAnh();
                data2.Image = "Images/product/" + FileUpload1.FileName;
                data.Manufacturer_Insert(data2);
                Alert.Text = Thongbao("Thêm thành công");
                Response.Redirect("../Sanpham/Sanpham.aspx");
            }
        
        
    }
    public string Thongbao(string text)
    { 
        return "<script>alert('"+text+"')</script>";
    }
    public void UploadAnh()
    {
        if (FileUpload1.HasFile)
        {
            FileUpload1.SaveAs(Server.MapPath("~/Images/product/"+FileUpload1.FileName));
        }
    }
    //public void InsertAnh()
    //{
    //    if (FileUpload1.FileName.Length > 0)
    //    {
    //        UploadAnh();
    //        data2.Image = "Images/product/" + FileUpload1.FileName;
    //    }
    //    else
    //    {
    //        data2.Image = txtHinhanhloaisanpham.Text;
    //    }
        
    //}
}